<!DOCTYPE html>
<html lang="en">
<head>
    <script src="/static/js/dev.js"></script>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--bootstrap插件-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link href="/static/plugin/bootstrap/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="/static/plugin/jo/joUI.css" rel="stylesheet"/>
    <!--字体插件-->
    <link href="/static/plugin/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="/static/plugin/layui-2.4.3/css/layui.css" rel="stylesheet"/>
    <!--ztree-->
    <link href="/static/plugin/zTree/css/metroStyle/metroStyle.css" rel="stylesheet"/>
    <!--common-->
    <link href="/static/css/common.css" rel="stylesheet"/>

    <title>线程池管理</title>
    <style>
        .threadpool-title {
            font-size: 14px;
            font-weight: 550;
            letter-spacing: 1px;
        }

        .threadpool-title-icon {
            color: #ff4c52;
        }

        .threadpool-title-icon-success {
            color: #11C26D;
        }

        .threadpool-num {
            /*height: 100px;*/
            /*line-height: 40px;*/
            font-size: 38px;
            text-align: center;
            font-weight: 400;
            color: #37474f;
        }
    </style>
</head>
<body class="skin-default">

<div class="container-fluid">

    <div class="row">
        <div class="col-xs-3">
            <div class="card">
                <div class="card-title threadpool-title">
                    <i class="fa fa-area-chart threadpool-title-icon" aria-hidden="true"></i>
                    线程池总数
                </div>
                <div class="card-content threadpool-num" id="show_poolNum">
                    0
                </div>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="card">
                <div class="card-title threadpool-title">
                    <i class="fa fa-bar-chart-o threadpool-title-icon-success" aria-hidden="true"></i>
                    活跃线程总数
                </div>
                <div class="card-content threadpool-num" id="show_activeCount">
                    0
                </div>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="card">
                <div class="card-title threadpool-title">
                    <i class="fa fa-area-chart threadpool-title-icon" aria-hidden="true"></i>
                    等待任务总数
                </div>
                <div class="card-content threadpool-num" id="show_waitCount">
                    0
                </div>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="card">
                <div class="card-title threadpool-title">
                    <i class="fa fa-bar-chart-o threadpool-title-icon-success" aria-hidden="true"></i>
                    已完成任务总数
                </div>
                <div class="card-content threadpool-num" id="show_completedTaskCount">
                    0
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-title threadpool-title">
                    <i class="fa fa-bar-chart-o threadpool-title-icon-success" aria-hidden="true"></i>
                    线程池列表
                </div>
                <div class="card-content">
                    <div class="table-bar">
                        <!--grid-->
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover table-line-auto" id="mainList"
                                   dataUrl="/threadpool/client/list" deleteUrl=""
                                   formUrl="/page/monitor/thread/threadPoolForm.html">
                                <col field="_seq" title="#" width="5%" align="center"/>
                                <col field="poolName" title="线程池" width="20%" align="" event=""/>
                                <col field="{poolSizeClick} / {corePoolSizeClick} / {maxPoolSizeClick}"
                                     title="当前 / 核心 / 最大" width="15%"
                                     align=""/>
                                <col field="largestPoolSize" title="峰值线程数" width="15%" align=""/>
                                <col field="activeCount" title="活跃线程" width="12%" align=""/>
                                <col field="waitCount" title="等待任务" width="12%" align=""/>
                                <col field="completedTaskCount" title="已完成任务" width="15%" align=""/>
                                <col field="keepAliveTime" title="过期时间(秒)" width="12%" align=""/>
                                <col field="rejectedHandlerName" title="拒绝策略" width="20%" align=""/>
                                <col field="queueClassName" title="阻塞队列" width="20%" align=""/>
                            </table>
                        </div>
                        <!--/grid-->

                        <!--分页条-->
                        <div class="page-bar" gridId="mainList">

                        </div>
                        <!--/分页条-->
                    </div>
                </div>
            </div>

            <!--视图块-->
<!--            <div class="container-fluid card">-->
<!--                <div class="row">-->
<!--                    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">-->

<!--                    </div>-->
<!--                </div>-->

<!--            </div>-->

        </div>
    </div>




</div>

<!--配置信息-->
<script src="/static/js/config.js"></script>
<!--jquery-->
<script src="/static/plugin/jquery/jquery-3.3.1.js"></script>
<script src="/static/plugin/jquery/jquery.cookie.js"></script>
<!--bootstrap-->
<script src="/static/plugin/bootstrap/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
<script src="/static/plugin/other/html5shiv.js"></script>
<script src="/static/plugin/other/respond.min.js"></script>
<![endif]-->
<!--layui-->
<script src="/static/plugin/layui-2.4.3/layui.all.js"></script>
<!--ztree-->
<script src="/static/plugin/zTree/js/jquery.ztree.all.js"></script>
<!--common-->
<script src="/static/js/common.js"></script>
<!--jo-->
<script src="/static/plugin/jo/jo.js"></script>
<script src="/static/plugin/jo/jo-adapt.js"></script>
<script src="/static/plugin/jo/jo-page-view.js"></script>
<script src="/static/plugin/jo/jo-page-form.js"></script>
<script src="/static/plugin/jo/jo-listener.js"></script>
<script type="text/javascript">
    $(function () {
        stat = {
            poolNum: 0
            , completedTaskCount: 0
            , activeCount: 0
            , waitCount: 0
        };
        joView.init({grid: $("#mainList"), PKName: "poolName", checkStyle: 'none'});//初始化页面
        showStat();

        // 定时刷新
        window.setInterval(function () {
            stat = {
                poolNum: 0
                , completedTaskCount: 0
                , activeCount: 0
                , waitCount: 0
            };
            joView.reloadCurrentPage();
            showStat();
        }, 10000);
    });
    function showStat() {
        for (var k in stat) {
            $('#show_' + k).html(stat[k]);
        }
    }
    // 线程池状态
    var stat;
    joView.handleItem = function (item) {
        item.poolSizeClick = htmlWrap4Label(item.poolSize, 'label-primary');
        item.corePoolSizeClick = htmlWrap4Label(item.corePoolSize, 'label-info', 'updateThreadPool("' + item.poolName + '", "corePoolSize", "核心线程数")');
        item.maxPoolSizeClick = htmlWrap4Label(item.maxPoolSize, 'label-warning', 'updateThreadPool("' + item.poolName + '", "maxPoolSize", "最大线程数")');

        stat.poolNum++;
        stat.completedTaskCount += item.completedTaskCount;
        stat.activeCount += item.activeCount;
        stat.waitCount += item.waitCount;
    }

    function updateThreadPool(poolName, type, tips) {
        jo.prompt({title: '修改' + tips}, function (val, idx) {
            jo.confirm('您确认要修改吗?', function (idx) {
                jo.postAjax('/threadpool/client/update', {poolName: poolName, type: type, value: val}, function (json) {
                    if (json && json.code == 0) {
                        jo.showSuccessMsg('修改成功:' + tips);
                        joView.reloadCurrentPage();
                    } else {
                        jo.showErrorMsg(jo.getDefVal(json.info, '修改失败'));
                    }
                }, true);
                jo.close(idx);
            });
            jo.close(idx);
        });
    }
</script>

</body>
</html>
